<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
<title>编辑子用户信息</title>
	<%@ include file="/resources/js/easyui/taglibs.jsp"%>
	<%@ include file="/resources/js/easyui/_easyui.jsp"%>
	<%@ include file="/resources/js/easyui/_message.jsp"%>
	<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
	<form name="editform" method="post" id="editform">
		<table class="tableForm" style="width: 100%;">

			<tr>
				<td align="right" valign="top"><span class="redStart">*</span><label>子帐号：</label></td>
				<td>${childuser.username}</td>
			</tr>

			<tr>
				<td align="right" valign="top"><span class="redStart">*</span><label>邮箱地址：</label></td>
				<td>
					<c:if test="${empty childuser.email}">
						<input class="easyui-textbox" type="email" name="email"
						style="width:200px" data-options="required:true,validType:'email'" />
					</c:if>
					<c:if test="${!empty childuser.email}">
						${childuser.email}
					</c:if>
				</td>
			</tr>

			<tr>
				<td align="right" valign="top"><span class="redStart">*</span><label>手机号：</label></td>
				<td>
					<c:if test="${empty childuser.mobile}">
						<input class="easyui-textbox" name="mobile"
					style="width:200px" data-options="required:true,validType:'mobile'" />
					</c:if>
					<c:if test="${!empty childuser.mobile}">
						${childuser.mobile}
					</c:if>
				</td>
			</tr>

			<tr>
				<td align="right" valign="top"><label>备注：</label></td>
				<td><input class="easyui-textbox" name="remark"
					style="width:200px;height:80px" data-options="multiline:true"
					value="${childuser.remark}" /></td>
			</tr>

			<tr>
				<td align="right" valign="top"><label>有效年限：</label></td>
				<td><input type="radio" name="timeDifference" value="1"
					<c:if test="${timeDifference == 1}">checked="checked"</c:if>>1年</input>
					<input type="radio" name="timeDifference" value="2"
					<c:if test="${timeDifference == 2}">checked="checked"</c:if>>2年</input>
					<input type="radio" name="timeDifference" value="3"
					<c:if test="${timeDifference == 3}">checked="checked"</c:if>>3年</input>
				</td>
			</tr>

			<tr>
				<td align="right" valign="top"><label>用户状态：</label></td>
				<td><input type="radio" name="state" value="1"
					<c:if test="${childuser.state == 1}">checked="checked"</c:if>>启用</input>
					<input type="radio" name="state" value="2"
					<c:if test="${childuser.state == 2}">checked="checked"</c:if>>停用</input>
				</td>
			</tr>
			<tr>
				<td align="right" valign="top"><label>重置密码：</label></td>
				<td>重置该用户为初始密码?<input type="button" value="重置"
					id="resetPassword" /></td>
			</tr>
			<input type="hidden" name="userid" value="${childuser.userid}" />
		</table>
	</form>
	<script type="application/javascript">
		
	$("#resetPassword").click(function(){

			$.messager.confirm('温馨提醒', '是否确定重置该用户的密码 ？', function (result) {  
		        if (result) {  
		  		  $.ajax({
		              url:'${basePath}web/childuser/resetChildUserPassword',
		              type : 'GET',
		              data : {"userid": $("[name='userid']").val()},
		              error: function (response) {
		                  ViewHelper.func.ajaxErrorMessage(response);
		              },
		              success: function (ret) {
		                  if(ret.result) {
		                      $.messager.alert('提示信息！',ret.info,'info');
		                      parent.view.closeEditWin(1);
		                      $("#editform").form('clear');
		                  }else{
		                      $.messager.alert('提示','保存失败!','error');
		                  }
		              }
		          });
		        }
		    }); 

	});
		
    function edit(){
        if($("#editform").form('validate')){
            $.ajax({
                url:'${basePath}web/childuser/editChildUser',
                type : 'POST',
                data : $("#editform").serialize(),
                async : false, //默认为true 异步
                traditional:true,
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        $.messager.alert('提示信息！',ret.info,'info');
                        parent.view.closeEditWin(1);
                        $("#editform").form('clear');
                    }else{
                        $.messager.alert('提示','保存失败!','error');
                    }
                }
            });
        }
    }
	
	/* 验证手机号码、用户名或邮箱是否存在 */
	function validatorDataOnlien(value){
		var result = true;
		$.ajax({
			url:'${basePath}web/childuser/vaildUserInfo',
			async: false, 
			type : 'GET',
            data: {"vaildatorValue": value},
			traditional:true,
			success: function (ret) {
				result = ret.vaildatorResult;
			}
		});
		return result;
	}
	
	$.extend($.fn.validatebox.defaults.rules, {
		email: {
			validator: function(value, param) {
				if(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)){
					if(validatorDataOnlien(value)){
						 
						 $.fn.validatebox.defaults.rules.email.message = '邮箱已经存在,请更换其他邮箱地址';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.email.message = '请输入正确的邮箱地址';
					return false;
				}
				return true;
			},
			message: ''
		},
		mobile: {
			validator: function(value, param) {
				if(/^(?:13\d|15\d|18\d|17\d|14\d)-?\d{5}(\d{3}|\*{3})$/.test(value)){
					if(validatorDataOnlien(value)){
						 
						 $.fn.validatebox.defaults.rules.mobile.message = '手机号码已经存在,请更换手机号码';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.mobile.message = '请输入正确的手机号码';
					return false;
				}
				return true;
			},
			message: ''
		},
		tel: {
			validator: function(value, param) {
				return /^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?(-\d{1,6})?$/.test(value);	
			},
			message: '请输入正确的固话电话号码'
		},
		mobileAndTel: {
			validator: function(value, param) {
				return /(^([0\+]\d{2,3})\d{3,4}\-\d{3,8}$)|(^([0\+]\d{2,3})\d{3,4}\d{3,8}$)|(^([0\+]\d{2,3}){0,1}13\d{9}$)|(^\d{3,4}\d{3,8}$)|(^\d{3,4}\-\d{3,8}$)/.test(value);
			},
			message: '请输入正确的联系电话或手机号码'
		},
		username : {// 只能输入英文和数字和特殊字符
			validator : function(value, param) {
				/* return /^[a-zA-Z0-9_]{1,}$/.test(value); */
				if(/^[a-zA-Z0-9_]{1,}$/.test(value)){
					if(validatorDataOnlien(value)){
						 $.fn.validatebox.defaults.rules.username.message = '用户名已经存在,请使用其他用户名';  
						 return false;
					}
				}else{
					$.fn.validatebox.defaults.rules.username.message = '请输入英文、数字或下划线';
					return false;
				}
				return true;
			},
			message : ''
		},
		passwordlegth: {
			validator: function (value) {
				return value.length >= 6;
			},
			message: '密码长度至少6位'
		},
		confirmPassword: {
			validator: function (value, param) {
				return value == $(param[0]).val();
			},
			message: '两次密码不一致'
		}
	});

	</script>
</body>
</html>
